import javax.crypto.*;

public class TripleDES
{
    TripleDES() {}

    public byte[] Encrypt(SecretKey key1, SecretKey key2, byte[] block) {
	
		DES des = new DES();
		byte[] cipher;
		
		try
		{
			cipher = des.Encrypt(key1, block);
			cipher = des.Decrypt(key2, cipher);
			cipher = des.Encrypt(key1, cipher);
			
			return cipher;
		}
		catch(Exception e) { System.out.println(e.toString()); }
		
		return null;
		
    }

    public byte[] Decrypt(SecretKey key1, SecretKey key2, byte[] block) {
		
		DES des = new DES();
		byte[] text;
		
		try
		{
			text = des.Decrypt(key1, block);
			text = des.Encrypt(key2, text);
			text = des.Decrypt(key1, text);
			 
			return text; 
		}
		catch(Exception e) { System.out.println(e.toString()); }
		
        return null;
    }
}




































